library(readr)
Beers <- read_csv("Beers.csv")## Parsed with column specification:
## cols(
## Name = col_character(),
## Beer_ID = col_double(),
## ABV = col_double(),
## IBU = col_double(),
## Brewery_id = col_double(),
## Style = col_character(),
## Ounces = col_double()
## )
head(Beers)## # A tibble: 6 x 7
## Name Beer_ID ABV IBU Brewery_id Style Ounces
## <chr> <dbl> <dbl> <dbl> <dbl> <chr> <dbl>
## 1 Pub Beer 1436 0.05 NA 409 American Pale Lager 12
## 2 Devil's Cup 2265 0.066 NA 178 American Pale Ale (… 12
## 3 Rise of the P… 2264 0.071 NA 178 American IPA 12
## 4 Sinister 2263 0.09 NA 178 American Double / I… 12
## 5 Sex and Candy 2262 0.075 NA 178 American IPA 12
## 6 Black Exodus 2261 0.077 NA 178 Oatmeal Stout 12
Beers## # A tibble: 2,410 x 7
## Name Beer_ID ABV IBU Brewery_id Style Ounces
## <chr> <dbl> <dbl> <dbl> <dbl> <chr> <dbl>
## 1 Pub Beer 1436 0.05 NA 409 American Pale Lager 12
## 2 Devil's Cup 2265 0.066 NA 178 American Pale Ale … 12
## 3 Rise of the P… 2264 0.071 NA 178 American IPA 12
## 4 Sinister 2263 0.09 NA 178 American Double / … 12
## 5 Sex and Candy 2262 0.075 NA 178 American IPA 12
## 6 Black Exodus 2261 0.077 NA 178 Oatmeal Stout 12
## 7 Lake Street E… 2260 0.045 NA 178 American Pale Ale … 12
## 8 Foreman 2259 0.065 NA 178 American Porter 12
## 9 Jade 2258 0.055 NA 178 American Pale Ale … 12
## 10 Cone Crusher 2131 0.086 NA 178 American Double / … 12
## # … with 2,400 more rows
library(readr)
Breweries <- read_csv("Breweries.csv")## Parsed with column specification:
## cols(
## Brew_ID = col_double(),
## Name = col_character(),
## City = col_character(),
## State = col_character()
## )
head(Breweries)## # A tibble: 6 x 4
## Brew_ID Name City State
## <dbl> <chr> <chr> <chr>
## 1 1 NorthGate Brewing Minneapolis MN
## 2 2 Against the Grain Brewery Louisville KY
## 3 3 Jack's Abby Craft Lagers Framingham MA
## 4 4 Mike Hess Brewing Company San Diego CA
## 5 5 Fort Point Beer Company San Francisco CA
## 6 6 COAST Brewing Company Charleston SC
summary(Beers)## Name Beer_ID ABV IBU
## Length:2410 Min. : 1.0 Min. :0.00100 Min. : 4.00
## Class :character 1st Qu.: 808.2 1st Qu.:0.05000 1st Qu.: 21.00
## Mode :character Median :1453.5 Median :0.05600 Median : 35.00
## Mean :1431.1 Mean :0.05977 Mean : 42.71
## 3rd Qu.:2075.8 3rd Qu.:0.06700 3rd Qu.: 64.00
## Max. :2692.0 Max. :0.12800 Max. :138.00
## NA's :62 NA's :1005
## Brewery_id Style Ounces
## Min. : 1.0 Length:2410 Min. : 8.40
## 1st Qu.: 94.0 Class :character 1st Qu.:12.00
## Median :206.0 Mode :character Median :12.00
## Mean :232.7 Mean :13.59
## 3rd Qu.:367.0 3rd Qu.:16.00
## Max. :558.0 Max. :32.00
##
summary(Breweries)## Brew_ID Name City State
## Min. : 1.0 Length:558 Length:558 Length:558
## 1st Qu.:140.2 Class :character Class :character Class :character
## Median :279.5 Mode :character Mode :character Mode :character
## Mean :279.5
## 3rd Qu.:418.8
## Max. :558.0
names(Beers)## [1] "Name" "Beer_ID" "ABV" "IBU" "Brewery_id"
## [6] "Style" "Ounces"
names(Breweries)## [1] "Brew_ID" "Name" "City" "State"
Beers <- rename(Beers, Brew_ID = Brewery_id)
names(Beers)## [1] "Name" "Beer_ID" "ABV" "IBU" "Brew_ID" "Style" "Ounces"
fullData <- full_join(Breweries, Beers, by = "Brew_ID")fullData## # A tibble: 2,410 x 10
## Brew_ID Name.x City State Name.y Beer_ID ABV IBU Style Ounces
## <dbl> <chr> <chr> <chr> <chr> <dbl> <dbl> <dbl> <chr> <dbl>
## 1 1 NorthGa… Minne… MN Get To… 2692 0.045 50 Americ… 16
## 2 1 NorthGa… Minne… MN Maggie… 2691 0.049 26 Milk /… 16
## 3 1 NorthGa… Minne… MN Wall's… 2690 0.048 19 Englis… 16
## 4 1 NorthGa… Minne… MN Pumpion 2689 0.06 38 Pumpki… 16
## 5 1 NorthGa… Minne… MN Strong… 2688 0.06 25 Americ… 16
## 6 1 NorthGa… Minne… MN Parape… 2687 0.056 47 Extra … 16
## 7 2 Against… Louis… KY Citra … 2686 0.08 68 Americ… 16
## 8 2 Against… Louis… KY London… 2685 0.125 80 Englis… 16
## 9 2 Against… Louis… KY 35 K 2684 0.077 25 Milk /… 16
## 10 2 Against… Louis… KY A Beer 2683 0.042 42 Americ… 16
## # … with 2,400 more rows
names(fullData)## [1] "Brew_ID" "Name.x" "City" "State" "Name.y" "Beer_ID" "ABV"
## [8] "IBU" "Style" "Ounces"
fullData <- rename(fullData, BreweryName = Name.x, BeerName = Name.y)
names(fullData)## [1] "Brew_ID" "BreweryName" "City" "State" "BeerName"
## [6] "Beer_ID" "ABV" "IBU" "Style" "Ounces"
fullData %>%
group_by(State) %>%
summarise(count = n())## # A tibble: 51 x 2
## State count
## <chr> <int>
## 1 AK 25
## 2 AL 10
## 3 AR 5
## 4 AZ 47
## 5 CA 183
## 6 CO 265
## 7 CT 27
## 8 DC 8
## 9 DE 2
## 10 FL 58
## # … with 41 more rows
BrewStatesC <- Breweries%>%
group_by(State)%>%
summarise(count = n())head(BrewStatesC)## # A tibble: 6 x 2
## State count
## <chr> <int>
## 1 AK 7
## 2 AL 3
## 3 AR 2
## 4 AZ 11
## 5 CA 39
## 6 CO 47
BrewStatesC## # A tibble: 51 x 2
## State count
## <chr> <int>
## 1 AK 7
## 2 AL 3
## 3 AR 2
## 4 AZ 11
## 5 CA 39
## 6 CO 47
## 7 CT 8
## 8 DC 1
## 9 DE 2
## 10 FL 15
## # … with 41 more rows
state.freq <- table(Breweries$State)
barplot(state.freq[order(state.freq)],
horiz = T,
border = NA,
xlim = c(0, 100),
main = "Number of Breweries per State",
xlab = "Number of Brewiews",
ylab = "States") #
# Number brewweries in each state:
state.freq##
## AK AL AR AZ CA CO CT DC DE FL GA HI IA ID IL IN KS KY LA MA MD ME MI MN MO
## 7 3 2 11 39 47 8 1 2 15 7 4 5 5 18 22 3 4 5 23 7 9 32 12 9
## MS MT NC ND NE NH NJ NM NV NY OH OK OR PA RI SC SD TN TX UT VA VT WA WI WV
## 2 9 19 1 5 3 3 4 2 16 15 6 29 25 5 4 1 3 28 4 16 10 23 20 1
## WY
## 4
names(state.freq)## [1] "AK" "AL" "AR" "AZ" "CA" "CO" "CT" "DC" "DE" "FL" "GA" "HI" "IA" "ID"
## [15] "IL" "IN" "KS" "KY" "LA" "MA" "MD" "ME" "MI" "MN" "MO" "MS" "MT" "NC"
## [29] "ND" "NE" "NH" "NJ" "NM" "NV" "NY" "OH" "OK" "OR" "PA" "RI" "SC" "SD"
## [43] "TN" "TX" "UT" "VA" "VT" "WA" "WI" "WV" "WY"
View(state.freq)## Warning in system2("/usr/bin/otool", c("-L", shQuote(DSO)), stdout = TRUE):
## running command ''/usr/bin/otool' -L '/Library/Frameworks/R.framework/
## Resources/modules/R_de.so'' had status 1
sDF<-data.frame(state.freq)
names(sDF)## [1] "Var1" "Freq"
sDF<- rename(sDF, State = Var1, NoBreweries=Freq)View(sDF)## Warning in system2("/usr/bin/otool", c("-L", shQuote(DSO)), stdout = TRUE):
## running command ''/usr/bin/otool' -L '/Library/Frameworks/R.framework/
## Resources/modules/R_de.so'' had status 1
names(Breweries)## [1] "Brew_ID" "Name" "City" "State"
p1 <- plot_ly(Breweries, x = ~State) %>% add_histogram()
p2 <-Breweries %>%
dplyr::count(State) %>%
plot_ly(x = ~n, y = ~State) %>%
add_bars(marker = list(color = 'rgba(170, 17, 19, 0.9)')) %>%
layout(title = "Number of Breweries by State",
legend = list(x = 0.03, y = 1.04))
subplot(p2)